﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;

public partial class QuarterPlan_AddQuarterSummary : System.Web.UI.Page
{
    UserInfo objUserInfo = new UserInfo();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Utility.HttpHelp.getParamsInt("Id") > 0)
            {
                object[] _value = new object[1];
                _value[0] = Utility.HttpHelp.getParamsInt("Id");
                DataTable dt = new BLL.QuarterSummary().GetSummaryById(_value);
                if (dt.Rows.Count > 0)
                {
                    this.txtQuarterSummary.Text = dt.Rows[0]["QuarterSummary"].ToString();
                    this.txtPreQuarterSummary.Text = dt.Rows[0]["PreQuarterSummary"].ToString();
                }
            }
        }
    }

    /// <summary>
    /// 添加上月总结
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (Utility.HttpHelp.getParamsInt("Id") == 0)
        {
            object[] _value = new object[6];
            _value[0] = Utility.HttpHelp.getParamsInt("QuarterDate");
            _value[1] = this.txtPreQuarterSummary.Text;
            _value[2] = this.txtQuarterSummary.Text;
            _value[3] = objUserInfo.UserName;
            _value[4] = "";
            _value[5] = Server.UrlDecode(Utility.HttpHelp.getParamsString("Department"));
            int val = new BLL.QuarterSummary().add(_value);
            if (val > 0)
            {
                Utility.HttpHelp.closeWindow(Utility.HttpHelp.getParamsString("Url") + "?Id=" + Utility.HttpHelp.getParamsInt("QuarterDate") + "&QuarterDate=" + Utility.HttpHelp.getParamsString("QuarterDate") + "&Year=" + Utility.HttpHelp.getParamsString("Year"), Page);

            }
            else
            {
                Utility.HttpHelp.alert("添加失败", this.Page);
            }
        }
        else
        {
            object[] _value = new object[7];
            _value[0] = Utility.HttpHelp.getParamsInt("Quarter");
            _value[1] = this.txtPreQuarterSummary.Text;
            _value[2] = this.txtQuarterSummary.Text;
            _value[3] = objUserInfo.UserName;
            BLL.UserInfoManager dllUserInfo = new BLL.UserInfoManager();
            DataTable dt = dllUserInfo.get(BLL.UserInfoManager.field.UserName.ToString(), new object[] { objUserInfo.UserName });
            _value[4] = Convert.ToInt32(dt.Rows[0]["UserId"]);
            _value[5] = Server.UrlDecode(Utility.HttpHelp.getParamsString("depart"));
            _value[6] = Utility.HttpHelp.getParamsInt("Id");
            int val = new BLL.QuarterSummary().editQuarterSummary(_value);
            if (val > 0)
            {
                Utility.HttpHelp.closeWindow(Utility.HttpHelp.getParamsString("Url") + "?Id=" + Utility.HttpHelp.getParamsInt("Quarter") + "&QuarterDate=" + Utility.HttpHelp.getParamsString("QuarterDate") + "&Year=" + Utility.HttpHelp.getParamsString("Year"), Page);

            }
            else
            {
                Utility.HttpHelp.alert("修改失败", this.Page);
            }
        }

    }
}